package com.woniu.tms.manage.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.tms.entity.Logform;
import com.woniu.tms.manage.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("manage/log")
public class LogController {

    @Autowired
    LogService logService;

    @RequestMapping("index")
    public String index() {
        return "WEB-INF/manage/logdo/index";
    }

    /**
     * 查询所有的操作记录日志
     *
     * @return
     */
    @RequestMapping("indexDo")
    @ResponseBody
    public Map<String, Object> indexDo(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                       String condition, String rname) {
        Map<String, Object> map = new HashMap<>();
        try {
            List<Logform> logformList = logService.list(condition, rname, pageNum, pageSize);
            PageInfo<Logform> pageInfo = new PageInfo<>(logformList);
            map.put("logformList", logformList);
            map.put("pageInfo", pageInfo);
            map.put("result", true);
        } catch (Exception e) {
            map.put("result", false);
        }
        return map;
    }

}
